package com.hzdl.library.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hzdl.library.domain.WeatherInfo;
import com.hzdl.library.util.WeatherUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/weatherServlet")
public class WeatherServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        String str_json = WeatherUtils.GetWeatherData("成都");
        WeatherInfo weatherInfo = WeatherUtils.GetWeather(str_json);
        objectMapper.writeValue(response.getOutputStream(),weatherInfo);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
